<?php

class App_Model_Database_Rules
extends Zend_Db_Table_Abstract
implements App_Model_Database_Rules_Interface
{
    /**
     * Role id
     * @var integer 
     */
    protected $_roleId;

    /**
     * Set role id and database connect
     * 
     * @param integer $roleId
     * 
     * @return void
     */
    public function __construct($roleId) {

        $this->setRoleId($roleId);
        parent::__construct();
    }

    /**
     *Set role id
     * 
     * @param integer $roleId
     * 
     * @return void
     */
    public function setRoleId($roleId)
    {
        $this->_roleId = (integer) $roleId;
    }

    /**
     * Get allow list
     * 
     * @return array
     * 
     * @return void
     */
    public function getAllow()
    {
        try {
            $allow = array();
            $query = $this->_db->select()
                               ->from("access_allow",
                                      array("resource", "privileg"));

            $result = $this->_db->fetchAll($query);

            foreach ($result as $key => $value) {
                $allow[$value["resource"]] = explode(",", $value["privileg"]);

            }
        
            return $allow;

        } catch (Zend_Exception $e) {

            error_log(print_r($e, true));
        }
    }
}